package com.mars.manager.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Restful API 访问路径 
 * http://IP:port/{context-path}/swagger-ui.html 
 * eg:http://localhost:8080/jd-config-web/swagger-ui.html 
 * eg:http://www.mars.com/swagger-ui.html
 * 
 * @类名 CustomSwaggerConfig
 * @日期 2016年12月27日 上午11:18:12
 * @作者 yhaoquan
 * @版权 (c) All Rights Reserved, 2016.
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig extends WebMvcConfigurationSupport {
	
	@Bean
	public Docket api() {
		return new Docket(DocumentationType.SWAGGER_2)
				.select()
				.apis(RequestHandlerSelectors.basePackage("com.mars.manager.web.controller"))
				.paths(PathSelectors.any())
				.build()
				.apiInfo(apiInfo());
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder()
				.title(this.getServletContext().getServletContextName() + " RESTful APIs")
				.description("")
				.termsOfServiceUrl("Terms of service")
				.contact(new Contact("杨浩泉", "http://www.mars.com", "yhaoquan@163.com"))
				.version("1.0")
				.build();
	}

}
